package com.chen.springboot.controller.uniapp;

import com.chen.springboot.dto.uniapp.Categories;
import com.chen.springboot.dto.uniapp.Category;
import com.chen.springboot.dto.uniapp.CategoryItem;
import com.chen.springboot.service.Impl.uniapp.CategoryItemService;
import com.chen.springboot.service.Impl.uniapp.CategoryService;
import com.chen.springboot.common.Result;  // 导入 Result 类
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = {"首页接口实现"})
@RestController
@RequestMapping("/api")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;
    @Autowired
    private CategoryItemService categoryItemService;

    // 获取所有分类
    @GetMapping("/categories")
    @ApiOperation("九宫图的分类列表")
    public Result<List<Categories>> getCategories() {
        List<Categories> categories = categoryService.getAllCategories();
        return Result.success(categories);  // 使用 Result 来包装返回值
    }

    // 获取所有分类项
    @GetMapping("/items")
    @ApiOperation("四个推荐的分类项列表")
    public Result<List<CategoryItem>> getCategoryItems() {
        List<CategoryItem> categoryItems = categoryItemService.getCategoryItems();
        return Result.success(categoryItems);
    }

    // 根据关键词搜索分类项
    @GetMapping("/search")
    @ApiOperation("搜索分类项")
    public Result<List<CategoryItem>> searchCategoryItems(@RequestParam String keyword) {
        List<CategoryItem> categoryItems = categoryItemService.searchCategoryItemsByKeyword(keyword);
        return Result.success(categoryItems);
    }
    // 获取分类树

    // 获取商品分类详情
    @GetMapping("/category/top")
    @ApiOperation("获取商品分类详情")
    public Result<List<Category>> getCategoryHierarchy() {
        List<Category> data = categoryService.getCategoryHierarchy();
        return Result.success(data);
    }

}
